package com.ruoyi.web.controller.comment;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.comment.domain.SystComment;
import com.ruoyi.comment.service.ISystCommentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 评论信息Controller
 *
 * @author zhezhi
 * @date 2022-10-02
 */
@RestController
@RequestMapping("/commerce/comment")
public class SystCommentController extends BaseController
{
    @Autowired
    private ISystCommentService systCommentService;

    /**
     * 查询评论信息列表
     */
    @PreAuthorize("@ss.hasPermi('commerce:comment:list')")
    @GetMapping("/list")
    @ApiOperation("查询评论信息列表")
    public TableDataInfo list(SystComment systComment)
    {
        startPage();
        List<SystComment> list = systCommentService.selectSystCommentList(systComment);
        return getDataTable(list);
    }

    /**
     * 导出评论信息列表
     */
    @PreAuthorize("@ss.hasPermi('commerce:comment:export')")
    @Log(title = "评论信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出评论信息列表")
    public void export(HttpServletResponse response, SystComment systComment)
    {
        List<SystComment> list = systCommentService.selectSystCommentList(systComment);
        ExcelUtil<SystComment> util = new ExcelUtil<SystComment>(SystComment.class);
        util.exportExcel(response, list, "评论信息数据");
    }

    /**
     * 获取评论信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('commerce:comment:query')")
    @GetMapping(value = "/{commentId}")
    @ApiOperation("获取评论信息详细信息")
    public AjaxResult getInfo(@PathVariable("commentId") Long commentId)
    {
        return AjaxResult.success(systCommentService.selectSystCommentByCommentId(commentId));
    }

    /**
     * 新增评论信息
     */
    @PreAuthorize("@ss.hasPermi('commerce:comment:add')")
    @Log(title = "评论信息", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增评论信息")
    public AjaxResult add(@RequestBody SystComment systComment)
    {
        return toAjax(systCommentService.insertSystComment(systComment));
    }

    /**
     * 修改评论信息
     */
    @PreAuthorize("@ss.hasPermi('commerce:comment:edit')")
    @Log(title = "评论信息", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改评论信息")
    public AjaxResult edit(@RequestBody SystComment systComment)
    {
        return toAjax(systCommentService.updateSystComment(systComment));
    }

    /**
     * 删除评论信息
     */
    @PreAuthorize("@ss.hasPermi('commerce:comment:remove')")
    @Log(title = "评论信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{commentIds}")
    @ApiOperation("删除评论信息")
    public AjaxResult remove(@PathVariable Long[] commentIds)
    {
        return toAjax(systCommentService.deleteSystCommentByCommentIds(commentIds));
    }
}
